package com.chinafree.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chinafree.permission.model.po.PermissionPO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @description: TODO
 * @author: longzix
 * @modified By: longzix
 * @date: Created in 2021/7/23 15:35
 * @version:v1.0
 */

public interface PermissionMapper  extends BaseMapper<PermissionPO> {

//    @Select("select id,name,type,permission_value,order,status from acl_permission where is_deleted =0 and id in "
//        + "(select permission_id from acl_role_permission where is_deleted =0 and role_id = #{roleId})")
//
//

    @Select("select `id`,`name`,`type`,`permission_value`,`order`,`status` from acl_permission where is_deleted =0 "
        + "and id in (select `permission_id` from acl_role_permission where deleted =0 and role_id = #{roleId})")
    List<PermissionPO> selectPermissionListByRoleId(@Param("roleId") Integer roleId);


    @Select("select `id`,`name`,`type`,`permission_value`,`order`,`status` from acl_permission where deleted =0 ")
    List<PermissionPO> selectPermissionList();


    @Select({
        "<script>",
        " select `id`,`name`,`type`,`permission_value`,`order`,`status` from acl_permission where deleted =0 and `id` in",
        "<foreach collection='permissionIdList' item='permissionId' open='(' separator=',' close=')'>",
        "#{permissionId}",
        "</foreach>",
        "</script>"
    })
    List<PermissionPO> selectPermissionListByPermissionIdList(@Param("permissionIdList") List<Integer> permissionIdList);


    @Select({
        "<script>",
        "select distinct permission_id from acl_role_permission where is_deleted =0 and role_id in",
        "<foreach collection='roleIdList' item='roleId' open='(' separator=',' close=')'>",
        "#{roleId}",
        "</foreach>",
        "</script>"
    })
    Set<Integer> selectPermissionIdListByRoleIdList(@Param("roleIdList") Set<Integer> roleIdList);
}
